package com.caoji.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caoji.advice.lyExcption;
import com.caoji.entity.SpecGroupDTO;
import com.caoji.entity.SpecParamDTO;
import com.caoji.item.entity.SpecGroup;
import com.caoji.item.entity.SpecParam;
import com.caoji.item.mapper.SpecParamMapper;
import com.caoji.item.service.SpecParamService;
import jdk.nashorn.internal.ir.CallNode;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {


    @Override
    public void addparam(SpecParamDTO paramDTO) {
        save(paramDTO.toEntity(SpecParam.class));
    }

    @Override
    public List<SpecParamDTO> querybybrandid(Long gid, Long cid, Boolean searching) {
        List<SpecParam> list = query().eq(cid != null,"category_id", cid)
                .eq(gid!= null,"group_id", gid)
                .eq(searching != null, "searching", searching).list();
        return SpecParamDTO.convertEntityList(list);
    }

    @Override
    public void updateparam(SpecParamDTO paramDTO) {
        updateById(paramDTO.toEntity(SpecParam.class));
    }

    @Override
    public List<SpecParamDTO> slectall(SpecGroupDTO specGroup, Long cid) {


        List<SpecParamDTO> list = SpecParamDTO.convertEntityList(query().eq("category_id", cid)
                .eq("group_id", specGroup.getId()).list());
        return list;
    }

}
